package ltd.newbee.mall.service.impl;

import ltd.newbee.mall.common.ServiceResultEnum;
import ltd.newbee.mall.dao.ShopMapper;
import ltd.newbee.mall.entity.NewBeeMallGoods;
import ltd.newbee.mall.entity.Shop;
import ltd.newbee.mall.entity.Video;
import ltd.newbee.mall.service.ShopService;
import ltd.newbee.mall.util.PageQueryUtil;
import ltd.newbee.mall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Zcq
 * @create: 2022-09-14 20:07
 **/
@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    ShopMapper shopMapper;


    @Override
    public PageResult getShopPage(PageQueryUtil pageUtil) {
        List<Shop> shops = shopMapper.findShopList(pageUtil);
        int total = shopMapper.getTotalShops(pageUtil);
        PageResult pageResult = new PageResult(shops, total, pageUtil.getLimit(), pageUtil.getPage());
        return pageResult;

    }

    @Override
    public String addShop(Shop shop) {
        if (shopMapper.addShop(shop) > 0) {
            return ServiceResultEnum.SUCCESS.getResult();
        }
        return ServiceResultEnum.DB_ERROR.getResult();
    }

    @Override
    public String upadateShop(Shop shop) {
        if (shopMapper.updateShop(shop) > 0) {
            return ServiceResultEnum.SUCCESS.getResult();
        }
        return ServiceResultEnum.DB_ERROR.getResult();
    }

    @Override
    public List<NewBeeMallGoods> FindGoodsByShopId(Integer shopId) {
        List<NewBeeMallGoods> goods = shopMapper.FindGoodsByShopId(shopId);
        return goods;
    }
}
